import re
import tkinter
import tkinter.messagebox
from Tkinter import *
from tkMessageBox import *
def get_data():
    try:
        content1=float(entry1.get())
        content2=float(entry2.get())
        return content1,content2
    except ValueError:
        raise ValueError
    def add():
        try:
            a,b=get_data()
            showinfo('add',str(a+b))
        except ValueError:
            showerror('error','a or b is error')

    def sub():
        try:
            a,b=get_data()
            showinfo('sub',str(a-b))
        except ValueError:
            showerror('error','a or b is error')
    def mul():
        try:
            a,b=get_data()
            showinfo('mul',str(a*b))
        except ValueError:
            showerror('error','a or b is error')
    def div():
        try:
            a,b=get_data()
            showinfo('div',str(a/b))
        except ValueError:
            showerror('error','a or b is error')
        except :
            showerror('error','a or b is error')
root = Tk()
label = Label(root,text='Calculator')
label.pack(side=TOP)
entry1=Entry(root)
entry1.pack()
entry2=Entry(root)
entry2.pack()
button1=Button(root,text='Add',command=add)
button1.pack(expand=YES,fill=BOTH)
button2=Button(root,text='Sub',command=sub)
button2.pack(expand=YES,fill=BOTH)
button3=Button(root,text='Mul',command=mul)
button3.pack(expand=YES,fill=BOTH)
button4=Button(root,text='Div',command=div)
button4.pack(expand=YES,fill=BOTH)
root.mainloop()
